import { Container, Graphics, IDestroyOptions, Texture } from "pixi.js";
import { DragPaint } from "../../utils/DragPaint";
import { Canvas } from "../Canvas";
import { alpha0 } from "../Constant";
import { hub } from "../hub";
import { useDraw } from "../utils/useDraw";
export class Cover extends Graphics {
    draw;
    /** 创建一个图层 */
    constructor(public canvas: Canvas, width: number, height: number) {
        super();

        this.beginFill(0xffffff, alpha0)
            .drawRect(0, 0, width, height)
            .endFill();
        this.interactive = true; //响应交互
        this.interactiveChildren = true;
        this.buttonMode = true; //鼠标变手型
        this.zIndex = 999999;

        // this.draw 内部有自己的销毁事件
        this.draw = useDraw(this, true);
        // 拖拽填充
        hub.on("DropColorFill", this.dropColorFill);
    }
    destroy(options?: boolean | IDestroyOptions): void {
        this.draw.stop();
        super.destroy.call(this, options);
        hub.off("DropColorFill", this.dropColorFill);
    }
    resize() {
        this.height = this.parent.height;
        this.width = this.parent.width;
    }
    dropColorFill = (callback: Function) => {
        // ! 注意 在移动端跨 DOM 拖拽会没有 pointerup 事件,所以改为这种方式
        const draw = DragPaint(this);
        callback(draw);
        // console.log("拖拽 Pixi ==> Cover");
    };
    /** 将画布挂载到 Pixi */
    mount(app: Container) {
        app.addChild(this);
        return this;
    }
}
